<?php
declare (strict_types = 1);

namespace app\model\communal;

use think\Model;
use think\model\relation\BelongsTo;

/**
 * Class app\model\communal\InviteModel
 */
class InviteModel extends Model
{
    /**
     * 数据库配置
     *
     * @var string
     */
    protected $connection = 'communal';

    /**
     * 主键
     *
     * @var string
     */
    protected $pk = 'id';

    /**
     * 表名
     *
     * @var string
     */
    protected $table = '55600_user_invite';

    /**
     * 自动时间戳
     *
     * @var bool
     */
    protected $autoWriteTimestamp = true;

    /**
     * 时间字段设置
     *
     * @var string
     */
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';

    /**
     * 展示字段名
     *
     * @var string[]
     */
    public static $column = ['id', 'from', 'to', 'created_at'];

    /**
     * 搜索字段名
     *
     * @var string[]
     */
    public static $searchColumn = ['id', 'from'];

    /**
     * 被邀请人关联用户
     *
     * @return BelongsTo
     */
    public function belongToUser()
    {
        return $this->belongsTo(UserModel::class, 'to', 'id')
            ->removeOption('soft_delete')
            ->bind([
                'to_avatar' => 'avatar',
                'to_mobile' => 'mobile',
            ]);
    }
}
